package com.x.mvp.utils;

import android.text.TextUtils;

import java.text.DecimalFormat;

/**
 * Created by H on 17/11/7.
 */

public class ValueOfUtils {
    static final DecimalFormat decimalFormat = new DecimalFormat("0.00");

    static final DecimalFormat decimalFormatO = new DecimalFormat("0.0");

    public static float floatValueOf(String str) {
        float ret = 0;
        if (TextUtils.isEmpty(str)) {
            return 0;
        }

        try {
            ret = Float.valueOf(str);
        } catch (Exception e) {

        } finally {
            return ret;
        }
    }

    public static int intValueOf(String str) {
        int ret = -1;
        if (TextUtils.isEmpty(str)) {
            return ret;
        }
        try {
            ret = Integer.valueOf(str);
        } catch (Exception e) {

        } finally {
            return ret;
        }
    }

    public static String formatFloatPrecent(float f) {
        return decimalFormat.format(f * 100) + "%";
    }

    public static String formatFloatOne(float f) {
        return decimalFormatO.format(f);
    }

}
